<?php
/**
 * 商品控制器
 * 
 * @version $Id: Item.php 679 2013-02-20 02:28:13Z linsir123 $
 */
class controllerItem extends AppController 
{
	/**
	 * 商品明细
	 */
	public function actionInfo()
	{
		$iId = $this->_getIid();
		$this->_checkCompatible($iId);
		
		///
		$mItem = M::item();
		$mShop = M::shop();
		
		///
		$item = $mItem->getInfo($iId);
		if (empty($item)) 
			$this->goto301();
			
		///
		$shop = $mShop->getOne($item['nick']);
		
		///
		$items = $mItem->getTaobaokes(array('show'=>9,'cid'=>$item['cid'],
			'sort'=>'commissionVolume_desc'), true);
			
		$shops = $mShop->getTaobaokes(array('show'=>24,'cid'=>$shop['cid'],
			'sortField'=>'commission_rate'), true);
			
		/// 关键字
		$keywords = M::keyword()->getList($item['cid'], 10);
		if ( ! empty($keywords)) 
			$keyMeta = implode(",", $keywords);
		else 
			$keyMeta = $item['title'];
			
		///
		AppView::addCss('themes/01/item.css');
		View::display('item/index');
		View::assignSet(array(
			'item' => $item, 
			'shop' => $shop, 
			'items' => $items[0], 
			'shops' => $shops[0], 
			'keyMeta' => $keyMeta, 
		));
	}
	
	/**
	 * 页面跳转
	 */
	public function actionJump()
	{
		$iId = $this->_getIid();
		
		/// 日志
		$this->log('Jump', null);
		
		///
		View::display('item/jump');
		View::assignSet(array(
			'id' => $iId
		));
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 取得商品ID
	 */
	private function _getIid()
	{
		$iId = trim($_GET['iid']);
		if ( ! preg_match("/^[\d]+$/", $iId) || ! is_numeric($iId)) 
			$this->goto301();
			
		///
		return $iId;
	}
	
	/**
	 * 兼容处理
	 */
	private function _checkCompatible($iId)
	{
		$tmp = Helper::itemAttach($iId);
		
		///
		$attach = trim($_GET['attach']);
		if ($attach != $tmp) {
			$url = Route::urlItem(array('iid'=>$iId));
			lpSystem::h301($url);
		}
	}
}
